#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <list>

#define fi first
#define se second
#define endl '\n'

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef pair<string, int> psi;

typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pss> vpss;
typedef vector<vi> vvi;

typedef queue <int> qi;
typedef queue <ll> ql;
typedef queue <pii> qpii;
typedef queue <psi> qpsi;

typedef priority_queue<int> pqi;
typedef priority_queue<string> pqs;
typedef priority_queue<pii> pqpii;
typedef priority_queue<psi> pqpsi;

typedef unordered_map<int, int> umapii;
typedef unordered_map<string, int> umapsi;

const int MAXN = 1e5 + 5;

void solve()
{
	int n;
	cin >> n;
	vl nums(n + 1);
	vpll temp(n + 1);
	vl ans(n + 1);
	vl sums(n + 1);
	for (int i = 1; i <= n; i++)
	{
		cin >> nums[i];
		temp[i].first = nums[i];
		temp[i].second = i;
	}
	if (nums.size() == 1)
	{
		cout << 0 << endl;
		return;
	}
	temp[0] = { 0,0 };
	temp.push_back({ INT32_MAX,n + 1 });
	sort(temp.begin(), temp.end());
	for (int i = 1; i < n; i++)
	{
		sums[i] = temp[i].first + sums[i - 1];
	}
	int start = 1;
	int en = 1;
	for (int i = 1; i <= n; i++)
	{
		if (sums[i] < temp[i + 1].first)
		{
			en = i;
			for (int j = start; j <= en; j++)
			{
				ans[temp[j].second] = i - 1;
			}
			start = i + 1;
		}
	}
	for (int i = 1; i <= n; i++)
	{
		cout << ans[i] << " ";
	}
	cout << endl;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int t = 1;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}